package com.interview.function;



import java.math.BigDecimal;
import java.util.function.*;

/**
 * java自带的常用函数和接口
 */
public class Test {
    public static void main(String[] args) {

        /**
         * Predicate test判断真假,判断谁的真假,判断什么条件的
         */
        Predicate<Integer> predicate = x -> x > 185;
        Student student = new Student("9龙", 23, 195);
        System.out.println(predicate.test(student.getHeight()));

        /**
         * 输出一个值
         */
        Consumer<String> consumer = System.out::println;
        consumer.accept("我命由我不由天");

        /**
         * 获得student对象的名字
         */
        Function<Student,String> function = Student::getName;
        String name = function.apply(student);
        System.out.println(name);
        /**
         * 获得student对象的身高
         */
        Function<Student,Integer> f1 = Student::getHeight;
        Integer height = f1.apply(student);
        System.out.println(height);

        /**
         * 工厂方法
         */
        Supplier<Integer> supplier = () -> Integer.valueOf(BigDecimal.TEN.toString());
        System.out.println(supplier.get());

        /**
         * 逻辑非(!)
         */
        UnaryOperator<Boolean> unaryOperator = uglily-> !uglily;
        Boolean apply = unaryOperator.apply(true);
        System.out.println(apply);

        BinaryOperator<Integer> operator = (x, y) -> x * y;
        Integer interger = operator.apply(2, 3);
        System.out.println(interger);

        test(()->"我是一个演示的函数式接口");

    }

    public static  void test(Worker worker){
        String work = worker.work();
        System.out.println(work);
    }
    public interface Worker{
        String work();
    }
}
